import requests
import json

json_data = ''

# 将JSON字符串解析为Python字典
data = json.loads(json_data)

name_key_map = {}

# 获取座位信息
seats = data['data']['userAuth']['reserve']['libs'][0]['lib_layout']['seats']

# 将座位名和对应的 key 存入字典
for seat in seats:
    name = seat['name']
    key = seat['key']
    if name:
        name_key_map[name] = key
print(name_key_map)

file_name = data['data']['userAuth']['reserve']['libs'][0]['lib_id']
print("图书馆id"+str(file_name))
# 写入文本文件
with open('../seatId/'+str(file_name), 'w', encoding='utf-8',) as file:
    for name, key in name_key_map.items():
        file.write(f"{name}: {key}\n")